<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * Class User
 * @package app\model
 */
class User extends Model
{
    // 模型切换数据库
    //protected $connection = 'mysql';
    public function getCookie()
    {
        $res = $this->find(1);
        return $res->getAttr('cookie');
    }
    // 获取器
    public function getSexAttr($value,$data)
    {
        $status = ['1'=>'男',2=>'未知',0=>'女'];
        return $status[$value];
    }
    // 动态查询5条数据
    public function scopeGetQuery($query)
    {
        return $query->where([])->limit(2)->order('create_time','desc')->field(true);
    }
    public function scopeName($query,$value)
    {
        return $query->where('name','like','%'.$value.'%');
    }
}
